package tcu.ead2021.watermanage.service;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import tcu.ead2021.watermanage.dao.DrinkDao;
import tcu.ead2021.watermanage.entity.Drink;

import java.util.List;
import java.util.UUID;

@Service
@RequiredArgsConstructor
public class DrinkService {
    private final DrinkDao drinkDao;

    public List<Drink> FindAll(){
        return drinkDao.selectAll();
    }

    public Drink getById(String id){
        return drinkDao.selectById(id);
    }

    public void addOne(Drink drink){
        drink.setId(UUID.randomUUID().toString());
        drinkDao.insert(drink);
    }

    public void updateById(String id,Drink drink){
        if(drinkDao.selectById(id)==null){
            throw new RuntimeException("更新失败，饮料信息不存在");
        }

        drink.setId(id);
        drinkDao.updateById(drink);
    }

    public void removeById(String id){
        drinkDao.deleteById(id);
    }
}
